<template>
  <div class="me">
    <div class="user">
      <div class="user-info">
        <img :src="userInfo.photo_url" class="user-Avatar" mode="aspectFill" v-if="loginState">
        <img src="../../../../static/images/me.png" class="user-Avatar" mode="aspectFill" @click="navigateToLogin" v-else>
        <div class="user-info-content">
          <div class="user-name" v-if="loginState">{{userInfo.user_vip.realname}}</div>
          <div class="user-name" v-if="!loginState" @click="navigateToLogin">点击登录账号</div>
          <div class="user-position" v-if="loginState">{{userInfo.user_vip.vip_name}}</div>
          <div class="user-integral" v-if="loginState">{{userInfo.integral}}积分</div>
        </div>
      </div>
      <div class="user-edit">
        <span @click="navigateToMemberInformation">编辑资料</span>
        <i class="user-edit-icon"></i>
      </div>
    </div>
    <div class="middle-container">
      <div class="middle-person-card" @click="navigateToMemberCard(user_id)">
        <img src="../../../../static/images/person_card.png">
        <span class="middle-text">个人名片</span>
      </div>
      <div class="middle-me-company" @click="navigateToMycompany">
        <img src="../../../../static/images/me_company.png">
        <span class="middle-text">我的企业</span>
      </div>
    </div>
    <div style="margin-bottom: 18rpx;">
      <Mecell leftText="我的积分" :clickCell="navigateToMyIntegral" :mecellLeftIcon="require('../../../../static/images/my_jifen.png')"/>
      <Mecell leftText="我的活动" :clickCell="navigateToRegistered" :mecellLeftIcon="require('../../../../static/images/my_activity.png')"/>
      <Mecell leftText="申请经费"  :clickCell="navigateToApplicationForm" :mecellLeftIcon="require('../../../../static/images/outlay.png')"/>
      <Mecell leftText="更换绑定手机"  :clickCell="navigateToResetPhone" :mecellLeftIcon="require('../../../../static/images/mobile.png')"/>
      <Mecell leftText="财务管理" v-if="userInfo.is_admin==1" :clickCell="navigateToFinancialManagement" :mecellLeftIcon="require('../../../../static/images/financial.png')"/>
      <Mecell leftText="费用审核" v-if="userInfo.is_admin==1" :clickCell="navigateToApplicationFormList" :mecellLeftIcon="require('../../../../static/images/appliaction.png')"/>
    </div>
    <div class="kefu-cell">
      <div class="kefu-btn-box">
        <img src="../../../../static/images/my_kefu.png">
        <button open-type="contact" class="kefu">联系客服</button>
      </div>
      <i class="mecell-icon icomoon-iconfont-platform-entrance"></i> 
    </div>
    <!-- <Mecell leftText="帮助中心" :mecellLeftIcon="require('../../../../static/images/help.png')"/> -->
  </div>
</template>

<script>
import Mecell from '../../../components/mecell.vue'
import {mapState} from 'vuex';
export default {
  data(){
    return{
      userInfo: {
        user_vip:{
          vip_name: '',
          company_info:{
            industry:'',
            visitor_count:'',
            contact_count:'',
          }
        }
      },
      user_id:'',
      loginState: false,
    }
  },
  components:{
    Mecell
  },
  onShow(){
    this.reqUserInfo();
  },
  computed: {
  },
  methods:{
    async reqUserInfo(){
      let user_token = wx.getStorageSync('userToken');
      let params = {};
      if(user_token){
        this.loginState = true;
        params.user_token = user_token;
        let res = await this.$api.getUserInfo(params);
        if(res.data.level == "success"){
          let data = res.data.data.user_info;
          this.userInfo = data;
          this.user_id = this.userInfo.user_id;
        }else{
          wx.showToast({
            title: res.data.message,
            icon: 'none',
            duration: 1000
          })
        }
      }
    },
    //跳转到个人名片
    navigateToMemberCard(id){
      if(!this.loginState){
        this.$currency.showToast('请先登录');
        return
      }
      wx.navigateTo({
        url: '/pages/meMain/memberCard/main?id='+ id
      })
    },
    //跳转我的企业
    navigateToMycompany(){
      if(!this.loginState){
        this.$currency.showToast('请先登录');
        return
      }
      if(this.userInfo.user_vip.is_vip==0){
        this.$currency.showToast('非会员不可填写');
        return;
      }
      wx.navigateTo({
        url: '/pages/meMain/myCompany/main'
      })
    },
    //跳转会员等级
    navigateToMemberRating(){
      if(!this.loginState){
        this.$currency.showToast('请先登录');
        return
      }
      wx.navigateTo({
        url: '/pages/meMain/memberRating/main'
      })
    },
    //跳转到已报名活动页面
    navigateToRegistered(){
      if(!this.loginState){
        this.$currency.showToast('请先登录');
        return
      }
      wx.navigateTo({
        url: '/pages/activityMain/registered/main'
      })
    },
    //跳转到我的积分
    navigateToMyIntegral(){
      if(!this.loginState){
        this.$currency.showToast('请先登录');
        return
      }
      wx.navigateTo({
        url: '/pages/meMain/myIntegral/main'
      })
    },
    //跳转重置电话
    navigateToResetPhone(){
      if(!this.loginState){
        this.$currency.showToast('请先登录');
        return
      }
      wx.navigateTo({
        url: '/pages/meMain/resetPhone/main'
      })
    },
    //跳转报名活动
    navigateToRegistered(){
      if(!this.loginState){
        this.$currency.showToast('请先登录');
        return
      }
      wx.navigateTo({
        url: '/pages/activityMain/registered/main'
      })
    },
    //跳转填写个人信息
    navigateToMemberInformation(){
      if(!this.loginState){
        this.$currency.showToast('请先登录');
        return
      }
      wx.navigateTo({
        url: '/pages/meMain/memberInformation/main'
      })
    },
    //跳转申请费用
    navigateToApplicationForm(){
      if(!this.loginState){
        this.$currency.showToast('请先登录');
        return
      }
      if(this.userInfo.user_vip.is_vip==0){
        this.$currency.showToast('非会员不可申请费用');
        return;
      }
      wx.navigateTo({
        url: '/pages/meMain/applicationForm/main'
      })
    },
    //跳转财务管理
    navigateToFinancialManagement(){
      if(!this.loginState){
        this.$currency.showToast('请先登录');
        return
      }
      wx.navigateTo({
        url: '/pages/meMain/financialManagement/main'
      })
    },
    //跳转费用审核
    navigateToApplicationFormList(){
      if(!this.loginState){
        this.$currency.showToast('请先登录');
        return
      }
      wx.navigateTo({
        url: '/pages/meMain/applicationFormList/main'
      })
    },
    //跳转登录页面
    navigateToLogin(){
      wx.navigateTo({
        url: '/pages/homeMain/login/main'
      })
    },
  },
  onLoad(){
    // setTimeout(()=>{
    //   console.log(this.userInfo)
    // },5000)
  }
}
</script>

<style lang="scss" scoped>
  .me{
    min-height: 100vh;
    background-color: #f1f1f1;
    .user{
      color: #fff;
      background: #2aa7e1;
      height:235rpx;
      padding: 0 40rpx;
      display: flex;
      justify-content: space-between;
      align-items: center;
      .user-info{
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 0;
        .user-Avatar{
          width: 144rpx;
          height: 144rpx;
          border-radius: 50%;
          margin-right: 18rpx;
        }
        .user-info-content{
          .user-name{
            font-size: 32rpx;
            height: 50rpx;
            line-height: 50rpx;
            font-weight: bold;
          }
          .user-position,
          .user-integral{
            font-size: 24rpx;
            height: 34rpx;
            line-height: 34rpx;
          }
        }
      }
      .user-edit{
        font-size: 30rpx;
        display: flex;
        justify-content: center;
        align-items: center;
        .user-edit-icon{
          width: 46rpx;
          height: 46rpx;
          background-image: url(../../../../static/images/me_icon.png);
          background-repeat: no-repeat;
          background-position: center center;
          background-size: 100% 100%;
        }
      }
    }
    .middle-container{
        background: #fff;
        height: 200rpx;
        display: flex;
        justify-content: center;
        align-items: center;
        margin-bottom: 20rpx;
        .middle-person-card,
        .middle-me-company{
          flex: 1;
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: center;
          img{
            width: 90rpx;
            height: 90rpx;
            border-radius: 50%;
            margin-bottom: 10rpx;
          }
          .middle-text{
            font-size: 30rpx;
          }
        }
      }
  }
  .kefu-cell{
    display: flex;
    justify-content: space-between;
    align-items: center;
    background:#fff;
    padding: 0 40rpx;
    font-size: 28rpx;
    margin-bottom: 2rpx;
    .kefu-btn-box{
      display: flex;
      justify-content: center;
      align-items: center;
      img{
        width: 40rpx;
        height: 40rpx;
        margin-right: 8rpx;
      }
      .kefu{
        width: 580rpx;
        background-color: #fff;
        height: 75rpx;
        font-size: 28rpx;
        padding: 0;
        color:#6d6c6c;
        text-align: left;
      }
      .kefu::after{
        border: none;
      }
    }
    .mecell-icon{
      color: #6d6c6c;
      transform:rotate(-90deg);
    }
  }
</style>